/**
 * 
 */
package net.sf.cldsql.dj.utl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;


/**
 * MultipleValueMap
 */
public class MultipleValueMap<K, V> {
    public HashMap<K, List<V>> map = new HashMap<K, List<V>>();
    public V get (K key) {
        List<V> list = this.map.get(key);
        V ret;
        if (list == null) {
            ret = null;
        } else if (list.size() > 1) {
            throw new DiException("only one value should return by getHeader.");
        } else {
            ret = list.get(0);
        }
        return ret;
    }
    public List<V> gets (K key) {
        return this.map.get(key);
    }
    public void put (K key, final V value) {
        if (map.get(key) != null) {
            map.get(key).add(value);
        } else {
            map.put(key, new ArrayList<V>() {
                public static final long serialVersionUID = 1L;
            {add(value);}});
        }
    }
    public List<V> put (K key, final List<V> valueList) {
        return map.put(key, valueList);
    }
    public Set<K> keySet() {
        return map.keySet();
    }
    public List<V> remove(K key) {
        return map.remove(key);
    }
}
